﻿@using hc.epm.ViewModel;
@model MonitorView
@{
    ViewBag.Title = "提报结果";
}
<style>
    .datalist tr td {
        padding: 2px;
    }

        .datalist tr td input[type="text"] {
            width: 100%;
            height: 100%;
            border: 1px solid #ccc;
            padding: 0 10px;
            box-sizing: border-box;
        }

    .selectpicker {
        width: 100%;
        height: 100%;
    }
</style>
<body>
    <div class="contentData">
        <form id="mainForm">
            <div class="tab">
                <div class="long-text">
                    <label for="PrejectName"><span class="star">*</span>&nbsp;项目名称&nbsp;:</label>
                    <input type="text" id="ProjectName" name="ProjectName" value="@Model.Monitor.ProjectName" disabled autocomplete="off" />
                    <i class="pic iconfont" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                    <input type="hidden" name="projectId" id="projectId" value="@Model.Monitor.ProjectId" />
                </div>
                <div class="long-text">
                    <label for="Title"><span class="star">*</span>&nbsp;检查标题&nbsp;:</label>
                    <input type="text" id="Title" name="Title" disabled value="@Model.Monitor.Title" />
                </div>
                <div class="intro">
                    <div><label><span class="star">*</span>&nbsp;检查说明&nbsp;:</label></div>
                    <div>
                        <textarea class="sub-description" disabled>@Model.Monitor.Content</textarea>
                    </div>
                </div>
                <div class="contract">
                    <div><label><span class="star">*</span>&nbsp;检查项&nbsp;:</label></div>
                    <table class="datalist" style="width:88%">
                        <thead>
                            <tr>
                                <th width="25%">资料名称</th>
                                <th width="25%">结果</th>
                                <th width="25%">备注</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (Model.MonitorDetails != null && Model.MonitorDetails.Count() > 0)
                            {
                                foreach (var item in Model.MonitorDetails)
                                {
                                    <tr>
                                        <td>@item.Name</td>
                                        @if (item.MonitorResultNo == "0")
                                        {
                                            <td>不合格</td>
                                        }
                                        else if (item.MonitorResultNo == "1")
                                        {
                                            <td>合格</td>
                                        }
                                        else if (item.MonitorResultNo == "2")
                                        {
                                            <td>良好</td>
                                        }
                                        else
                                        {
                                            <td></td>
                                        }
                                        <td>@item.Remark</td>
                                    </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
                <div class="long-text">
                    <label for="Result"><span class="star">*</span>&nbsp;检查结果&nbsp;:</label>
                    <select style="width:230px;background-color:#EBEBE4" name="Result" id="Result" disabled>
                        <option value="0">请选择</option>
                        <option value="1">通过</option>
                        <option value="2">需整改</option>
                    </select>
                    <input type="hidden" name="result" id="result" value="@Model.Monitor.Result" />
                </div>
                @if (Model.MonitorDetailBIM != null && Model.MonitorDetailBIM.Any())
                {
                    var first = Model.MonitorDetailBIM.First();
                    <div class="long-text">
                        <label>&nbsp;关联BIM&nbsp;:</label>
                        <input type="text" id="SelectBIM" name="SelectBIM" value="已关联构件" readonly style="color:blue; background-color:#EBEBE4;" />
                        <input type="hidden" id="bimId" value="@first.BIMId" />
                        <i class="pic iconfont SelectBIM_icon" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                    </div>
                }
                else
                {
                    <div class="long-text">
                        <label>&nbsp;关联BIM&nbsp;:</label>
                        <input type="text" value="未关联构件" disabled />
                        <i class="pic iconfont" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                    </div>
                }
                <div class="long-text MonitorCompanyName">
                    <label><span class="star">*</span>&nbsp;检查单位&nbsp;:</label>
                    <input type="text" id="MonitorCompanyName" name="MonitorCompanyName" disabled value="@Model.Monitor.MonitorCompanyName">
                    <i class="pic iconfont ff" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                    <input type="hidden" name="MonitorCompanyId" id="MonitorCompanyId" value="@Model.Monitor.MonitorCompanyId" />
                </div>
                <div class="long-text MonitorUserName">
                    <label><span class="star">*</span>&nbsp;检查人&nbsp;:</label>
                    <input type="text" id="MonitorUserName" name="MonitorUserName" value="@Model.Monitor.MonitorUserName" disabled>
                    <i class="pic iconfont ff" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                    <input type="hidden" name="MonitorUserId" id="MonitorUserId" value="@Model.Monitor.MonitorUserId" />
                </div>
                <div class="short-text">
                    <label><span class="star">*</span>&nbsp;检查日期&nbsp;:</label>
                    <input type="text" id="MonitorTime" name="MonitorTime" onClick="WdatePicker({ el: 'MonitorTime' })" disabled value="@(Model.Monitor.MonitorTime == null ? "" : Convert.ToDateTime(Model.Monitor.MonitorTime).ToString("yyyy-MM-dd"))">
                    <i onClick="WdatePicker({ el: 'MonitorTime' })" class="pic iconfont" width="20" height="30" style="cursor:pointer">&#xe7e2;</i>
                </div>
                <div class="upload">
                    <div><label>&nbsp;检查资料&nbsp;:</label></div>
                    <div style="width:100%;margin:3px 20px 20px 0px;" id="fileListFile">
                        <ul id="fileDetail" style="margin-top:0!important;width:100%"></ul>
                    </div>
                </div>
                <hr />
                <div class="short-text">
                    <label><span class="star">*</span>&nbsp;要求完成时间&nbsp;:</label>
                    <input type="text" id="Deadline" name="Deadline" onClick="WdatePicker({ el: 'Deadline' })" autocomplete="off" value="@(Model.MonitorRectifRecord.Deadline == null ? "" : Convert.ToDateTime(Model.MonitorRectifRecord.Deadline).ToString("yyyy-MM-dd"))" disabled>
                    <i onClick="WdatePicker({ el: 'Deadline' })" class="pic iconfont" width="20" height="30" disabled>&#xe7e2;</i>
                </div>
                <div class="intro suggest">
                    <div><label for="Rectification"><span class="star">*</span>&nbsp;整改建议&nbsp;:</label></div>
                    <div>
                        <textarea class="sub-description" id="Remark" name="Remark" disabled>@Model.MonitorRectifRecord.Remark</textarea>
                    </div>
                </div>
                <div class="short-text">
                    <label><span class="star">*</span>&nbsp;整改状态&nbsp;:</label>
                    @Html.DropDownList("State", ViewBag.RectificationState as SelectList)
                </div>
                <div class="short-text">
                    <label><span class="star">*</span>&nbsp;整改完成时间&nbsp;:</label>
                    <input type="text" id="FinishDate" name="FinishDate" onClick="WdatePicker({ el: 'FinishDate' })" autocomplete="off" value="">
                    <i onClick="WdatePicker({ el: 'FinishDate' })" class="pic iconfont" width="20" height="30" style="cursor:pointer;">&#xe7e2;</i>
                </div>
                <div class="intro">
                    <div><label for="Content"><span class="star">*</span>&nbsp;整改内容&nbsp;:</label></div>
                    <div>
                        <input type="hidden" name="Id" id="Id" value="@Model.MonitorRectifRecord.Id" />
                        <textarea class="sub-description" value="" id="Content" name="Content"></textarea>
                    </div>
                </div>
                <div class="upload" style="margin-bottom:0px;">
                    <div><label>&nbsp;整改资料&nbsp;:</label></div>
                    <div class="btn-upload">
                        <button id="btnUploadFile" style="position: relative; z-index: 1;">上传附件</button>
                        <span style="vertical-align:bottom; margin-left:15px; color:#B7B7B7;"></span>
                    </div>
                </div>
                <div style="width:100%;" id="fileListFile" class="fileListFile">
                    <ul class="fileShow"></ul>
                    <input type="hidden" name="fileDataJson" id="fileDataJson" value="">
                </div>
                <div class="button-group btn-center">
                    <button type="button" class="saveBut">提交</button>
                </div>
            </div>
        </form>
    </div>
    <script>
        $(function () {
            $("#mainForm").validate({
                errorClass: "validaterror",
                validClass: "validatevalid",
                errorElement: "span",
                success: function (label) {
                    label.addClass("validatevalid").html("&nbsp;");
                },
                rules: {
                    FinishDate: {
                        required: true,
                        date: true
                    },
                    Content: {
                        required: true,
                    },
                },
                messages: {
                    FinishDate: {
                        required: "整改完成时间不能为空",
                        date: "日期格式错误"
                    },
                    Content: {
                        required: "整改内容不能为空",
                    },
                }
            });

            //检查结果
            if ($("#result").val() == 0) {
                $("#Result option:selected").text("请选择");
                $(".suggest").hide();
            } else if ($("#result").val() == 1) {
                $("#Result option:selected").text("通过");
                $(".suggest").hide();
            } else if ($("#result").val() == "2") {
                $("#Result option:selected").text("需整改");
                $(".suggest").show();
            }
        })
        layui.use(['layer', 'form', 'element'], function () {
            var layer = layui.layer, element = layui.element, $ = layui.jquery;

            //确认
            $(".saveBut").click(function () {
                if ($("#mainForm").valid()) {
                    var search = $("form").serialize();
                    $.post("UploadRectifyResultZL", search, function (data) {
                        if (data.Flag) {
                            layer.msg("操作成功", { time: 1000, icon: 1 }, function () {
                                window.location.href = "/QualityMonitor/IndexZL";
                            });
                        } else {
                            layer.alert(data.Message, { icon: 2 });
                        }
                    });
                }
            });
            var fileDataArrayFile = [];
            var fileDataJsonFile = [];
            //获取附件
            $.post("/Files/GetFileList", { tableName: 'Epm_Monitor', id: '@Model.Monitor.Id' }, function (data) {
                if (data.Flag) {
                    if (data.Data.length > 0) {
                        data.Data.forEach(function (item, index, arr) {
                            if (item.ImageType == null) {
                                var odiv = '<li id="' + item.GuidId + '" style="width:100%">';
                                odiv += '<div><img src="' + getFileImg(item.Name) + '" style="width: 20px;height: 20px;cursor: pointer;" class="imgShow"/><a href="' + FileDownLoadURL + item.FileGuid + '" target="_blank">' + item.Name + '</a></div>';
                                odiv += '<div>' + Number(item.Size / 1024).toFixed(2) + 'kb</div>';
                                odiv += '<div class="fileComplete"><img src="/Resource/images/default_ok.png" alt="完成" /></div>';
                                odiv += '</li>';
                                $('#fileListFile #fileDetail').append(odiv);
                            }
                        });
                    }
                } else {
                    parent.layer.alert(data.Message, { icon: 2 });
                }
            });
            //附件上传
            var fileDataArrayFile = [];
            var fileDataJsonFile = [];
            //附件上传
            var uploaderFile = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4', // 这里是说用什么技术引擎
                url: FileServerURL, // 服务端上传路径
                max_file_size: MaxFileSize, // 文件上传最大限制。
                max_file_count: 10, //指示用户可以同时上传文件的最大数量
                chunk_size: 0, // 上传分块每块的大小，这个值小于服务器最大上传限制的值即可,0表示不启用分块。
                browse_button: 'btnUploadFile',//触发上传元素
                flash_swf_url: '/Resource/scripts/plupload_2_1_2/Moxie.swf',
                silverlight_xap_url: '/Resource/scripts/plupload_2_1_2/Moxie.xap',
                multi_selection: true,//	是否可以在文件浏览对话框中选择多个文件
                multipart_params: {//附加参数
                    app: 'epm',
                    crop: true
                },
                //  这个数组是选择器，就是上传文件时限制的上传文件类型，在chrome下有bug，要等待
                filters: {
                    mime_types: [
                        { title: "Doc files", extensions: "doc,docx,xls,xlsx,rar,zip,7z,gif,rmvb,mp4,avi,jpg,png,jpeg" },
                    ],
                    max_file_size: MaxFileSize, //最大只能上传100mb的文件
                    prevent_duplicates: true //不允许选取重复文件
                },
                rename: false, // 是否重命名文件
                init: {
                    PostInit: function () { },
                    FilesAdded: function (uploaderFile, files) {
                        if (files) {
                            files.forEach(function (item, index, arr) {
                                var imgUrl = getFileImg(item.name);
                                var odiv = '<li id="' + item.id + '">';
                                odiv += '<div><img src="' + imgUrl + '" style="width: 20px;height: 20px;cursor: pointer;" class="imgShow"/><a href="javascript:;" target="_blank">' + item.name + '</a></div>';
                                odiv += '<div>' + plupload.formatSize(item.size) + '</div>';
                                odiv += '<div class="fileComplete"><span class="fileProgress" style="cursor: pointer;">' + item.percent + '</span>%</div>';
                                odiv += '<div><img src="/Resource/images/delete_default.png" class="fileDel" data-val="' + item.id + '" style="cursor: pointer;"/></div>'
                                odiv += '</li>';
                                $('#fileListFile .fileShow').append(odiv);
                            })
                            uploaderFile.start();
                        }
                    },
                    UploadProgress: function (uploaderFile, file) {
                        $("#" + file.id).find(".fileProgress").html(file.percent)
                    },
                    FileUploaded: function (uploaderFile, file, responseObject) {
                        var data = JSON.parse(responseObject.response);
                        data.file.forEach(function (item, index, arr) {
                            var obj = {};
                            obj.GuidId = file.id;
                            obj.Name = item.Name;
                            obj.Size = item.FileSize;
                            obj.FileGuid = item.Guid;
                            obj.Url = item.VirtualURL;
                            if (IsImage(item.Extension)) {
                                obj.ImageType = getImageType(item.Name, item.Extension);
                            }
                            fileDataArrayFile.push(obj);
                        })
                        var img = '<img src="/Resource/images/default_ok.png" alt="完成" />'
                        $("#" + file.id).find(".fileComplete").html(img);
                        $("#" + file.id).find("a").prop("href", FileDownLoadURL + data.file[0].Guid)
                        uploaderFile.removeFile(file);
                    },
                    UploadComplete: function (uploaderFile, file, responseObject) {
                            fileDataJsonFile = JSON.stringify(fileDataArrayFile);
                            $("#fileDataJson").val(fileDataJsonFile);
                    },
                    Error: function (up, err) {
                        layer.alert("错误：" + err.code + ": " + err.message);
                    }
                },

            });
            uploaderFile.init();
            //删除附件
            $(".fileListFile").on("click", ".fileDel", function () {
                $(this).parents("li").remove();
                var toremove = '';
                var id = $(this).data("val");
                //----删除初始文件对应的值
                fileDataArrayFile = fileDataArrayFile.filter(function (item, index, arr) {
                    return item.GuidId != id
                })
                fileDataJsonFile = JSON.stringify(fileDataArrayFile);
                $("#fileDataJson").val(fileDataJsonFile);
            });

            //BIM模型展示
            $("#SelectBIM,.SelectBIM_icon").click(function () {
                var bimId = $("#bimId").val();
                var monitorId = '@Model.Monitor.Id';
                layer.open({
                    type: 2,
                    title: GetLayerTitle("查看BIM模型"),
                    shadeClose: false, //点击遮罩关闭层
                    area: ['1300px', '800px'],
                    content: '/Monitor/RelationBIM?bimId=' + bimId,
                    btn: ["返回"],
                    success: function (layero, index) {
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.init(monitorId, bimId);
                    },
                    yes: function (index, layero) {
                        layer.close(index);
                    },
                    btn2: function (index, layero) {

                    },
                    cancel: function (index, layero) {
                    },
                });
            })
        });
    </script>
</body>
